<%--
  Created by IntelliJ IDEA.
  User: 风间琉璃
  Date: 2021/6/3
  Time: 19:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <h1>办公楼门禁管理系统</h1>
  <a href="add.jsp"><button>办卡</button></a>
  <table>
    <tr style=background-color:bisque>
      <th>姓名</th>
      <th>身份证</th>
      <th>状态</th>
      <th>日期</th>
      <th>操作</th>
    </tr>
    <c:forEach items="${list}" var="c" varStatus="s">
      <tr>
        <td>${c.userName}</td>
        <td>${c.idNumber}</td>
        <td class="statusStr">${c.status == 1 ? "启用":"禁用"}</td>
        <td>${c.createDate}</td>
        <td>
          <a class="update" attr_id="${c.id}" href="javascript:void(0)">${c.status == 2 ? "启用":"禁用"}</a>
          <a class="del" attr_id="${c.id}" href="javascript:void(0)">删除</a>
        </td>
      </tr>
    </c:forEach>
  </table>
  <a href="CardMybatisServlet?pageIndex=1">首页</a>
  <c:if test="${pageIndex gt 1}">
    <a href="CardMybatisServlet?pageIndex=${pageIndex - 1}">上一页</a>
  </c:if>
  当前处于${pageIndex}页，共有${pageCount}页
  <c:if test="${pageIndex lt pageCount}">
    <a href="CardMybatisServlet?pageIndex=${pageIndex + 1}">下一页</a>
  </c:if>
  <a href="CardMybatisServlet?pageIndex=${pageCount}">尾页</a>
  </body>
<script src="js/jquery-1.8.3.js"></script>
<script>

  $(document).ready(function () {
    $(".update").click(function (){
      var node = $(this);
      var node1 = $(this).parent().prev().prev();
      var id = $(this).attr("attr_id");
      var status = this.text == "禁用" ? 2 : 1;
      var str = status == 1 ? "禁用":"启用";
      var nodeStr = status == 1 ? "启用":"禁用";
      $.post("CardMybatisServlet?opr=update","status="+status+"&id="+id,function (param){
        alert(param);
        node.text(str);
        node1.text(nodeStr);
      });
    })
    $(".del").click(function (){
      var node = $(this);
      var id = $(this).attr("attr_id");
      $.post("CardMybatisServlet?opr=del","id="+id,function (param){
        alert(param);
        if (param == "删除成功"){
          node.parent().parent().remove();
        }
      })
    })
  })
</script>
</html>
